package com.imedia.frame.lucene.utils;

import java.util.Iterator;
import java.util.List;

import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;

/**
 * <p>
 * Title: 全站检索
 * </p>
 * <p>
 * Description: HTML数据处理工具类
 * </p>
 * <p>
 * Copyright: Copyright (c) 2009
 * </p>
 * <p>
 * Company: 
 * </p>
 * 
 * @author qiuy
 * @version 1.0
 */
public class HTMLDataUtils {
	
	/**
	 * <p>description: 得到str字符串中 tagName标签下的所有内容</p>
	 * @param str
	 * @param tagName
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static String getReallyString(String str,String tagName) {
		
		StringBuffer resultStringBuffer = new StringBuffer();
		
		HtmlCleaner cleaner = new HtmlCleaner();

		TagNode tagNode = null;

		try {
			tagNode = cleaner.clean(str);
			List tagNodes = tagNode.getElementListByName(tagName, true);
			for (Iterator iterator = tagNodes.iterator(); iterator.hasNext();) {
				TagNode tagNodeSub = (TagNode) iterator.next();
				Object objectString = tagNodeSub.getText();
				if (objectString != null) {
					resultStringBuffer.append(objectString);
				}
			}
		} catch (Exception e) {
			System.out.println(">>>>>>>>>>>>>>>> get really content exception");
			e.printStackTrace();
		}
		return resultStringBuffer.toString();
	}
}
